package com.vincent.kdp.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vincent.baseapp.util.DateUtil;
import com.vincent.kdp.R;
import com.vincent.kdp.ui.bean.response.NoticeAgentMatterListOutput;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/6/13 0013.
 */
public class NoticeListAdapter extends RecyclerView.Adapter<NoticeListAdapter.ViewHolder> {

    private Context context;
    private OnItemClicker onItemClicker;
    private int itemCount = 0;
    private List<NoticeAgentMatterListOutput.DataBean.ListBean> noticeList = new ArrayList<>();

    public NoticeListAdapter(Context context, OnItemClicker onItemClicker) {
        this.context = context;
        this.onItemClicker = onItemClicker;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        NoticeAgentMatterListOutput.DataBean.ListBean c = noticeList.get(position);
        /*Glide.with(context).load("http://" + c.getImage()).placeholder(R.mipmap.ic_commodity_one).into(holder.mCommodityImg);
        holder.mCommodityNameTv.setText(c.getName());
        holder.mPriceTv.setText("￥" + c.getPrice());*/
        holder.mNoticeItemContent.setText(c.getTitle());
        holder.mNoticeItemTime.setText(DateUtil.date2String(Long.parseLong(c.getAddtime()),"yyyy-MM-dd"));
        //holder.mNoticeItemTitle.setText(c.getId());
        holder.mNoticeItemTitle.setText(c.getTitle());

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false);
        return new ViewHolder(view, onItemClicker);
    }

    public void refreshData(List<NoticeAgentMatterListOutput.DataBean.ListBean> list) {
        noticeList.clear();
        noticeList = list;
        itemCount = noticeList.size();
    }

    public void addData(List<NoticeAgentMatterListOutput.DataBean.ListBean> list) {
        noticeList.addAll(list);
        itemCount = noticeList.size();
    }

    @Override
    public int getItemCount() {
        return itemCount;
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @Bind(R.id.notice_item_content)
        TextView mNoticeItemContent;
        @Bind(R.id.notice_item_time)
        TextView mNoticeItemTime;
        @Bind(R.id.notice_item_title)
        TextView mNoticeItemTitle;

        private OnItemClicker onCheckedItemClicker;

        public ViewHolder(View itemView, OnItemClicker onCheckedItemClicker) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
            this.onCheckedItemClicker = onCheckedItemClicker;
        }

        @Override
        public void onClick(View v) {
            onCheckedItemClicker.operate(v, getAdapterPosition());
        }
    }

    public interface OnItemClicker {
        void operate(View view, int position);
    }


}
